﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity.DSJCYD94;

namespace JM.JCY.SharePointComponent.CaseManagement.CaseDepartmentCase
{
    public partial class CaseDepartmentCaseUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (UserManagementProxy proxy = new UserManagementProxy())
                {
                    this.ddlDepartment.DataSource = proxy.GetAllDepartment();
                    ddlDepartment.DataTextField = "DeptName";
                    ddlDepartment.DataValueField = "DeptName";
                    ddlDepartment.DataBind();
                    ListItem lt = new ListItem();
                    lt.Text = "请选择一个部门..";
                    lt.Value = string.Empty;
                    ddlDepartment.Items.Insert(0, lt);
                }
            }
        }

        protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewDataBind();
        }

     

        protected void gvCaseWarning_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.gvCaseWarning.PageIndex = e.NewPageIndex;
            GridViewDataBind();
        }

        private void GridViewDataBind()
        {
            if (this.ddlDepartment.SelectedIndex != 0)
            {
                using (DSJCYD94Proxy proxy = new DSJCYD94Proxy())
                {
                    CaseManagementDataSet.T_AJGL_AJJK_BMAJDataTable dt = proxy.GetDepartmentCase(this.ddlDepartment.SelectedValue);
                    if (dt.Rows.Count > 0)
                        this.NoRecord.Visible = false;
                    else
                        this.NoRecord.Visible = true;

                    this.gvCaseWarning.DataSource = dt;
                    this.gvCaseWarning.DataBind();
                }
            }
        }
    }
}
